package com.eternal.users.controller;


import com.eternal.Exception.ResultEnum;
import com.eternal.Exception.ResultVo;
import com.eternal.users.service.UsersService;
import com.eternal.users.vo.UsersVo;
import com.eternal.util.page.PageVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 基础组织机构表 前端控制器
 * </p>
 *
 * @author Eternal
 * @since 2018-10-28
 */
@RestController
@RequestMapping("/users")
public class UsersController {

    @Autowired
    private UsersService usersService;

    @GetMapping("/queryUsersAll")
    @RequiresPermissions("users_queryUsersAll")
    public ResultVo<PageVo<UsersVo>> queryUsersAll(int current, int size){
        PageVo<UsersVo> stringObjectMap = usersService.queryUsersAllPage(current, size);
        return new ResultVo(stringObjectMap);
    }

    @GetMapping("/queryUsersAllByOrgId")
    @RequiresPermissions("users_queryUsersAllByOrgId")
    public ResultVo<PageVo<UsersVo>> queryUsersAllByOrgId(int current, int size,String orgId) {
        PageVo<UsersVo> stringObjectMap = usersService.queryUsersAllPage(current, size,orgId);
        return new ResultVo(stringObjectMap);
    }

    @GetMapping("/queryUsersAllByOrgIdParameter")
    @RequiresPermissions("users_queryUsersAllByOrgIdParameter")
    public ResultVo<PageVo<UsersVo>> queryUsersAllByOrgIdParameter(int current, int size,String orgId,String parameter) {
        PageVo<UsersVo> stringObjectMap = usersService.queryUsersAllPage(current, size,orgId,parameter);
        return new ResultVo(stringObjectMap);
    }


    @PostMapping("/importExcelUsers")
    @RequiresPermissions("users_importExcelUsers")
    public ResultVo importExcelUsers(MultipartFile file) {
        boolean excelOrg = usersService.importExcelUsers(file);
        return new ResultVo(excelOrg ? ResultEnum.SUCCESS : ResultEnum.IMPORT_ORGANIZE_ERROR);
    }

}

